#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#*===========================================================================*/
#*                                                                           */
#* Module Name:  rmcd_start                                                  */
#*                                                                           */
#* Description:                                                              */
#*      Script to start the Resource Monitor & Control Daemon                */
#*                                                                           */
#* N.B. This command is intended to be executed by the RMC subsystem only !! */
#*                                                                           */
#*===========================================================================*/
#*   @(#)58   1.4   src/rsct/rmc/mcdaemon/rmcd_start.sh, mcdaemon, rsct_rpyxh, rpyxht1f3 6/18/01 18:20:18 

PATH=/usr/sbin/rsct/install/bin:/usr/sbin/rsct/bin:/usr/bin:/usr/sbin:/bin
export PATH

FIRST=/var/ct/first_start
FIRST_LOG=/var/ct/first.log
START_PORT_FILE=/var/ct/cfg/ctrmc.rpe

SECSUBSYS=ctcas					# security subsystem daemon

# sed string to extract subsystem state from "lssrc -s <subsys>" output
PARSE_SRC_STATE="-e1d;s/.* \([a-zA-Z0-9]*\)$/\1/"

# if the first start file is present, start the ctfirst script in the
# background.

if [[ -a $FIRST ]]
then
	ctfirst > $FIRST_LOG 2>&1 &
fi

# check if remote clients are to be accepted

if [[ -a $START_PORT_FILE ]]
then
	ROPT="-r"

	# ensure security subsystem is running

	state=$(LC_ALL=C lssrc -s "$SECSUBSYS" | sed "$PARSE_SRC_STATE")
	if [[ -n "$state" && "$state" != "active" ]]
	then
		startsrc -I -s $SECSUBSYS
	fi
else
	ROPT=

	# ensure security subsystem is stopped

	state=$(LC_ALL=C lssrc -s "$SECSUBSYS" | sed "$PARSE_SRC_STATE")
	if [[ -n "$state" && "$state" = "active" ]]
	then
		stopsrc -c -s $SECSUBSYS
	fi
fi

# now start the RMC daemon in the current process so it is the child of the
# SRC subsystem daemon

exec /usr/sbin/rsct/bin/rmcd $ROPT $@

